package com.cls.business.service;

import com.cls.business.entity.*;
import com.cls.business.vo.DeclareTopicPreItemApplyExport;
import com.cls.business.vo.DeclareTopicVO;
import com.cls.business.vo.SelectEntrustVO;
import com.cls.common.entity.QueryRequest;
import com.github.pagehelper.PageInfo;
import com.baomidou.mybatisplus.extension.service.IService;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 申报课题表 Service接口
 *
 * @author weimaomao
 * @date 2020-11-10 11:09:57
 */
public interface IDeclareTopicService extends IService<DeclareTopic> {
    /**
     * 查询（分页）
     *
     * @param request      QueryRequest
     * @param declareTopic declareTopic
     * @return PageInfo<DeclareTopic>
     */
    PageInfo<DeclareTopicVO> findDeclareTopics(QueryRequest request, DeclareTopic declareTopic);

    /**
     * 查询（所有）
     *
     * @param declareTopic declareTopic
     * @return List<DeclareTopic>
     */
    List<DeclareTopic> findDeclareTopics(DeclareTopic declareTopic);

    List<DeclareTopic> findByTopicIds(List<Long> topicCodes);

    /**
     * 新增
     *
     * @param declareTopicVO declareTopicVO
     */
    void createDeclareTopic(DeclareTopicVO declareTopicVO);


    void updateCheckDeclareTopic(DeclareTopic declareTopic);

    /**
     * 修改
     *
     * @param declareTopicVo declareTopic
     */
    void updateDeclareTopic(DeclareTopicVO declareTopicVo);

    /**
     * 删除
     *
     * @param declareTopic declareTopic
     */
    void deleteDeclareTopic(DeclareTopic declareTopic);


    void updateDeclareTopicStatusTypeCode(DeclareTopic declareTopic, String operatorType);

    void applyDeclareTopicStatusTypeCode(DeclareTopic declareTopic, Long planId);

    PageInfo<DeclareTopicVO> findDeclareTopicsForEvaluation(QueryRequest request, DeclareTopic declareTopic);

    List<TopicSubjectDetail> countDeclareTopicsBySubjectType(Long topicId, String statusTypeCode);

    /**
     * 魏起成
     * 根据状态查询课题并根据年份分组
     *
     * @param statusTypeCode
     * @return
     */
    List<Topic> selectByStatusGroupByYear(String statusTypeCode,String topicClassfiy);

    /**
     * 魏起成
     * 根据年份查询此年份所有的拟立项审查通过的数据，进行生成编码并修改其状态为立项通过
     *
     * @param year
     */
    void createAnnualCode(Integer year);


    /**
     * 导出拟立项数据
     * @param userId
     * @param declareId
     * @param response
     */
    void exportPreItemApply(Long userId, Long declareId, HttpServletResponse response);
    /**
     * 导出委托申请书
     * @param declareId
     * @param response
     */
    void exportEntrustPreItemApply(Long declareId, HttpServletResponse response);
    /**
     * 导出结项申请书
     * @param declareId
     * @param response
     */
    void ConclusionEntrustApply(Long declareId, HttpServletResponse response);
    /**
     * 下载延期申请书
     * @param declareId
     * @param response
     */
    void exportDelayApply(Long declareId, HttpServletResponse response);
    void exportCertificate(Long declareId, HttpServletResponse response);
    void exportNotice(Long declareId, HttpServletResponse response);

    /**
     * 前端拟立项申请
     * @param
     * @param userId
     */
    void preItemApply(DeclareTopic declare, Long userId);

    /**
     * 新增或者修改委托课题
     * @param declareTopicVO
     */
    void createOrUpdateEntrustAdd(DeclareTopicVO declareTopicVO);

    void removeEntrustById(Long declareId);
    DeclareTopicVO findByIdVo(long declareId);

    void changeApplyDeclareTopicVO(DeclareTopicVO declareTopicVO);

//    PageInfo<SelectEntrustVO> chooseEntrusts(QueryRequest request, DeclareTopic declareTopic);

    PageInfo<SelectEntrustVO> chooseEntrusts(QueryRequest request, Long planId);

    PageInfo<SelectEntrustVO> assignEntrusts(QueryRequest request, Long planId);

    void updateConclusion(DeclarePlan declarePlan, String userName,Long entrustId);

    String getBlg(MaxIndex maxIndex);


    List<DeclareTopic> applyCapitalDeclareTopics();


    /**
     * 根据planid和状态查询年度课题
     * @param planId
     * @return
     */
    List<DeclareTopic> findAnnualDeclareTopicByPlanIdAndStatusTypeCode(Long planId,String statusTypeCode);

    /**
     * 魏起成
     * 根据申请课题查询用户
     * @param declareTopicId
     * @return
     */
    ApplicantInfo findApplicantInfoById(Long declareTopicId);

    /**
     * 魏起成
     * 查询登记和用户id  根据planID
     * @param planId
     * @return
     */
    List<DeclareTopic> findFinalLevelTypeAndUserIdByPlanId(Long planId);

    /**
     * 魏起成
     * 查询DeclareTopic  根据planID
     * @param planId
     * @return
     */
    List<DeclareTopic>  selectByPlanId(Long planId);

    /**
     * 查询举报的课题列表
     * @param planId
     * @return
     */
    List<DeclareTopic> reportListDeclareTopic(Long planId);

    /**
     * 导出拟立项结果
     * @param period
     * @param response
     */
    void exportPreItem(String period, HttpServletResponse response) throws IOException;
}
